//
//  UserMessageTableViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/26.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "UserMessageTableViewCell.h"

@interface UserMessageTableViewCell ()

@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIImageView *contentImage;
@property (nonatomic, strong) UIButton *repeatBtn;

@end

@implementation UserMessageTableViewCell

+ (UserMessageTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"UserMessageTableViewCell";
    UserMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UserMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(30), ScreenX375(20), ScreenX375(40), ScreenX375(40))];
    self.headImage.image = ImageWithName(@"头像2");
    self.headImage.clipsToBounds = YES;
    self.headImage.layer.cornerRadius = ScreenX375(20);
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(79), ScreenX375(25), ScreenX375(150), ScreenX375(18))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = Kfont(16);
    self.nameLabel.text = @"池鱼思故渊";
    [self addSubview:self.nameLabel];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(79), ScreenX375(51), ScreenX375(180), ScreenX375(30))];
    self.detailLabel.textColor = REXADECIMALCOLOR(@"#9b9b9b");
    self.detailLabel.font = Kfont(13);
    self.detailLabel.numberOfLines = 0;
    self.detailLabel.text = @"评论了你的作品“好看好看，我喜”欢的类型，简约大气，仙女风范，超喜欢虾拼里设计师的作品！";
    [self addSubview:self.detailLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(79), ScreenX375(100), ScreenX375(100), ScreenX375(14))];
    self.timeLabel.textColor = REXADECIMALCOLOR(@"#888888");
    self.timeLabel.font = Kfont(12);
    self.timeLabel.text = @"10小时前";
    [self addSubview:self.timeLabel];
    
    self.contentImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(80), ScreenX375(20), ScreenX375(64), ScreenX375(64))];
    self.contentImage.image = ImageWithName(@"组8");
    self.contentImage.contentMode = UIViewContentModeScaleAspectFill;
    self.contentImage.clipsToBounds = YES;
    [self addSubview:self.contentImage];
    
    self.repeatBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(80), ScreenX375(95), ScreenX375(64), ScreenX375(22))];
    [self.repeatBtn setTitle:@"回复" forState:UIControlStateNormal];
    [self.repeatBtn setTitleColor:REXADECIMALCOLOR(@"#4a90e2") forState:UIControlStateNormal];
    self.repeatBtn.titleLabel.font = Kfont(12);
    [self.repeatBtn addTarget:self action:@selector(repeat) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.repeatBtn];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(133) - 0.5, SCREEN_WIDTH - ScreenX375(32), 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
}

- (void)setUserMessageModel:(UserMessageModel *)userMessageModel {
    _userMessageModel = userMessageModel;
    
    if (_userMessageModel.appraiseId) {
        self.repeatBtn.hidden = NO;
    }else {
        self.repeatBtn.hidden = YES;
    }
    self.detailLabel.text = userMessageModel.content;
    CGFloat height = kGetStringHeight(userMessageModel.content, CGSizeMake(ScreenX375(180), ScreenX375(46)), Kfont(13));
    self.detailLabel.frame = CGRectMake(ScreenX375(79), ScreenX375(52), ScreenX375(180), height);
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:userMessageModel.senderPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.nameLabel.text = userMessageModel.senderName;
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:userMessageModel.proPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.timeLabel.text = [HttpManager getTime:[HttpManager TimeStamp:userMessageModel.modifyTime]];
}

- (void)repeat {
    if (_repeatClick) {
        _repeatClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation UserMessageModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end
